import { Column, Entity, JoinTable, ManyToMany } from 'typeorm';
import { BaseEntity } from '@src/common/entity/base.entity';
import { Role } from '@src/role/entity/role.entity';

@Entity({ name: 'users' })
export class User extends BaseEntity {
  @Column({ type: 'varchar', length: 100, unique: true, comment: '用户名' })
  username: string;

  @Column({ type: 'varchar', length: 100, comment: '密码' })
  password: string;

  @ManyToMany(() => Role, (role) => role.users, { eager: true, cascade: true })
  @JoinTable({
    name: 'user_role_relation',
    joinColumn: { name: 'user_id', referencedColumnName: 'id' },
    inverseJoinColumn: { name: 'role_id', referencedColumnName: 'id' },
  })
  roles: Role[];
}
